﻿using Fast.SqlSugar.Tenant.Repository;
using Fast.SqlSugar.Web.Model;
using Microsoft.AspNetCore.Mvc;

namespace Fast.SqlSugar.Web.Controllers;

[Route("[controller]/[action]")]
[ApiController]
public class TestController : Controller
{
    private readonly ISqlSugarRepository<SysTenantModel> _sysTenantRepository;

    public TestController(ISqlSugarRepository<SysTenantModel> sysTenantRepository)
    {
        _sysTenantRepository = sysTenantRepository;
    }

    [HttpGet]
    public async Task<List<SysTenantModel>> GetAll()
    {
        return await _sysTenantRepository.ToListAsync();
    }
    
    [HttpGet]
    public async Task<List<SysTenantModel>> GetAllByName(string tenantName)
    {
        return await _sysTenantRepository.ToListAsync(wh => wh.ChName.Contains(tenantName));
    }

    [HttpGet]
    public async Task AddTenant(string tenantName)
    {
        await _sysTenantRepository.InsertAsync(new SysTenantModel
        {
            ChName = tenantName,
            EnName = tenantName,
            ChShortName = tenantName,
            EnShortName = tenantName,
            Secret = "Fast.NET",
            AdminName = "Fast.Admin",
            Email = "2875616188@qq.com",
            Phone = "18888888888"
        });
    }
}